$(function(){
	childrenCompany();
	search();
});

var childrenCompany=function(){
	$.ajax({
		url : contextPath+ 'user/company/childrencompany',
		type : 'POST',
		success : function(list) {
			if(list!=null && list.length>0){
				$("#companyId").empty();
				var option="<option value ='0' >全部单位</option>";
				for(var i=0;i<list.length;i++){
					var company = list[i];
					option +="<option value='"+company.companyId+"'>"+company.companyName+"</option>";
				}
				$("#companyId").append(option);
			}
		}
	});
};

function search(){
	var companyId = $('#companyId').val();
	$.ajax({
		url : contextPath+ 'user/vzystat/listuser',
		data : {
			companyId : companyId
		},
		type : 'POST',
		success : function(list) {
			$("#content").empty();
			if(list!=null && list.length>0){
				var allzyxlmainlinecount					=0;	
				var allzyxlsublinecount           =0;
				var allzyxltotallinelength        =0;
				var allzyxloverheadlinelength     =0;
				var allzyxloverheadlinelengthBar  =0;
				var allzyxloverheadlinelengthCover=0;
				var allzyxlcablelength            =0;
				var allzygtcount                  =0;
				var alllxcount                    =0;
				var allpublicbyqcount             =0;
				var allpublicbyqcapacity          =0;
				var allprivatebyqcount            =0;
				var allprivatebyqcapacity         =0;
				var allzykgzcount                 =0;
				var allzypdscount                 =0;
				var allzyhwgcount                 =0;
				var allzyxsbdzcount               =0;
				var allzydlfzxcount               =0;
				var allzyzsdlqcount               =0;
				var allzyzsfhkgcount              =0;
				var allzyzsglkgcount              =0;
				var allzyzschqcount               =0;
				var allzyzsdlsrdqcount            =0;
				var allzyzsblqcount               =0;
				var allzyzsdrqcount               =0;
				var allzyzsdrqcapacity            =0;
				for(var i=0;i<list.length;i++){
					if(companyId=="0"){
					allzyxlmainlinecount		   +=list[i].zyxlmainlinecount			;	
					allzyxlsublinecount            +=list[i].zyxlsublinecount           ;
					allzyxltotallinelength         +=list[i].zyxltotallinelength        ;
					allzyxloverheadlinelength      +=list[i].zyxloverheadlinelength     ;
					allzyxloverheadlinelengthBar   +=list[i].zyxloverheadlinelengthBar  ;
					allzyxloverheadlinelengthCover +=list[i].zyxloverheadlinelengthCover;
					allzyxlcablelength             +=list[i].zyxlcablelength            ;
					allzygtcount                   +=list[i].zygtcount                  ;
					alllxcount                     +=list[i].lxcount                    ;
					allpublicbyqcount              +=list[i].publicbyqcount             ;
					allpublicbyqcapacity           +=list[i].publicbyqcapacity          ;
					allprivatebyqcount             +=list[i].privatebyqcount            ;
					allprivatebyqcapacity          +=list[i].privatebyqcapacity         ;
					allzykgzcount                  +=list[i].zykgzcount                 ;
					allzypdscount                  +=list[i].zypdscount                 ;
					allzyhwgcount                  +=list[i].zyhwgcount                 ;
					allzyxsbdzcount                +=list[i].zyxsbdzcount               ;
					allzydlfzxcount                +=list[i].zydlfzxcount               ;
					allzyzsdlqcount                +=list[i].zyzsdlqcount               ;
					allzyzsfhkgcount               +=list[i].zyzsfhkgcount              ;
					allzyzsglkgcount               +=list[i].zyzsglkgcount              ;
					allzyzschqcount                +=list[i].zyzschqcount               ;
					allzyzsdlsrdqcount             +=list[i].zyzsdlsrdqcount            ;
					allzyzsblqcount                +=list[i].zyzsblqcount               ;
					allzyzsdrqcount                +=list[i].zyzsdrqcount               ;
					allzyzsdrqcapacity             +=list[i].zyzsdrqcapacity            ;
					}
					var div = '<tr height="40">';
					//div += '<ul class="czrz_cont_ul">';
					div += '<td width="47">'+(i+1)+'</td>';
					div += '<td width="10%">'+list[i].companyName+'</td>';
					div +='<td width="66">'+list[i].zyxlmainlinecount          +'</td>';          
					div +='<td width="66">'+list[i].zyxlsublinecount           +'</td>';
					div +='<td width="66">'+list[i].zyxltotallinelength        +'</td>';
					div +='<td width="66">'+list[i].zyxloverheadlinelength     +'</td>';
					div +='<td width="66">'+list[i].zyxloverheadlinelengthBar  +'</td>';
					div +='<td width="66">'+list[i].zyxloverheadlinelengthCover+'</td>';
					div +='<td width="66">'+list[i].zyxlcablelength            +'</td>';
					div +='<td width="66">'+list[i].zygtcount                  +'</td>';
					div +='<td width="66">'+list[i].lxcount                    +'</td>';
					div +='<td width="66">'+list[i].publicbyqcount             +'</td>';
					div +='<td width="66">'+list[i].publicbyqcapacity          +'</td>';
					div +='<td width="66">'+list[i].privatebyqcount            +'</td>';
					div +='<td width="66">'+list[i].privatebyqcapacity         +'</td>';
					div +='<td width="66">'+list[i].zykgzcount                 +'</td>';
					div +='<td width="66">'+list[i].zypdscount                 +'</td>';
					div +='<td width="66">'+list[i].zyhwgcount                 +'</td>';
					div +='<td width="66">'+list[i].zyxsbdzcount               +'</td>';
					div +='<td width="66">'+list[i].zydlfzxcount               +'</td>';
					div +='<td width="66">'+list[i].zyzsdlqcount               +'</td>';
					div +='<td width="66">'+list[i].zyzsfhkgcount              +'</td>';
					div +='<td width="66">'+list[i].zyzsglkgcount              +'</td>';
					div +='<td width="66">'+list[i].zyzschqcount               +'</td>';
					div +='<td width="66">'+list[i].zyzsdlsrdqcount            +'</td>';
					div +='<td width="66">'+list[i].zyzsblqcount               +'</td>';
					div +='<td width="66">'+list[i].zyzsdrqcount               +'</td>';
					div +='<td width="66">'+list[i].zyzsdrqcapacity            +'</td>';
					//div += '</ul>';
					div += '</tr>';
					$("#content").append(div);
				}
				if(companyId=="0"){
				var end = '<tr height="40">';
				//end += '<ul class="czrz_cont_ul">';
				end += '<td width="47">合计</td>';
				end += '<td width="10%"></td>';
				end +='<td width="66">'+allzyxlmainlinecount					+'</td>';          
				end +='<td width="66">'+allzyxlsublinecount           +'</td>';
				end +='<td width="66">'+allzyxltotallinelength        +'</td>';
				end +='<td width="66">'+allzyxloverheadlinelength     +'</td>';
				end +='<td width="66">'+allzyxloverheadlinelengthBar  +'</td>';
				end +='<td width="66">'+allzyxloverheadlinelengthCover+'</td>';
				end +='<td width="66">'+allzyxlcablelength            +'</td>';
				end +='<td width="66">'+allzygtcount                  +'</td>';
				end +='<td width="66">'+alllxcount                    +'</td>';
				end +='<td width="66">'+allpublicbyqcount             +'</td>';
				end +='<td width="66">'+allpublicbyqcapacity          +'</td>';
				end +='<td width="66">'+allprivatebyqcount            +'</td>';
				end +='<td width="66">'+allprivatebyqcapacity         +'</td>';
				end +='<td width="66">'+allzykgzcount                 +'</td>';
				end +='<td width="66">'+allzypdscount                 +'</td>';
				end +='<td width="66">'+allzyhwgcount                 +'</td>';
				end +='<td width="66">'+allzyxsbdzcount               +'</td>';
				end +='<td width="66">'+allzydlfzxcount               +'</td>';
				end +='<td width="66">'+allzyzsdlqcount               +'</td>';
				end +='<td width="66">'+allzyzsfhkgcount              +'</td>';
				end +='<td width="66">'+allzyzsglkgcount              +'</td>';
				end +='<td width="66">'+allzyzschqcount               +'</td>';
				end +='<td width="66">'+allzyzsdlsrdqcount            +'</td>';
				end +='<td width="66">'+allzyzsblqcount               +'</td>';
				end +='<td width="66">'+allzyzsdrqcount               +'</td>';
				end +='<td width="66">'+allzyzsdrqcapacity            +'</td>';
				//end += '</ul>';
				end += '</tr>';
				$("#content").append(end);
				}
			}
		}
	});
}

function exportexcle(){
	var companyId = $('#companyId').val();
	if(confirm("确定导出对应数据吗？")){
		$("#exportimg").show();
		$.ajax({
			url : contextPath+ 'user/excel/vzystatlist',
			data : {
				companyId : companyId
			},
			type : 'POST',
			success : function(data) {
				$("#exportimg").hide();
				var uploadurl = basePath + data.msgDesc;
				//alert(uploadurl);
				if(data.opResult=='0'){
					window.location.href = uploadurl;
				}else{
					alert(data.msgDesc);
				}
			}
		});
	}
}
